package com.hl.service;

import com.hl.domain.Consultreply;
import com.hl.mapper.ConsultreplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsultreplyService {
    @Autowired
    private ConsultreplyMapper consultreplyMapper;

public List<Consultreply> reply(Long id){
    List<Consultreply> consultreplies = consultreplyMapper.floor1(id);
    for (Consultreply consultreply : consultreplies) {
        consultreply.setRname(getName(Long.valueOf(consultreply.getRuid())));
        List<Consultreply> replyzi = replyzi(consultreply.getId());
        consultreply.setConsultreplies(replyzi);
    }
    return consultreplies;
}

public List<Consultreply> replyzi(Long id){
    List<Consultreply> consultreplies = consultreplyMapper.floor2(id);
    for (Consultreply consultreply : consultreplies) {
        if (consultreply.getRuid()!=null){
            consultreply.setRname(getName(Long.valueOf(consultreply.getRuid())));
        }
    }

    return consultreplies;
}

public String getName(Long id){
    if (id!=null){
        return consultreplyMapper.getName(id);
    }
    return null;

}

    //添加回复
    public int addreply(Consultreply consultreply){
       return consultreplyMapper.insert(consultreply);
    }

    //新增
    public int insertSelective(Consultreply record){
        return consultreplyMapper.insertSelective(record);
    }
}
